package com.ayf.payment.game.api.controller.platform;

import com.ayf.payment.game.api.dto.platform.MerchantChannelDTO;
import com.ayf.payment.game.api.dto.platform.PaymentChannelDTO;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.service.platform.PaymentChannelService;
import com.ayf.payment.game.api.type.CommonConstants;
import com.ayf.payment.game.api.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通道设置
 *
 * @author wwl
 * @date 2020/3/7 12:32
 */
@RequestMapping("/t/payment")
@RestController
public class PaymentChannelController {

    @Autowired
    private PaymentChannelService paymentChannelService;

    /**
     * 获取通道列表
     * @return
     */
    @PostMapping("/channel/selectAll")
    public CommonResult<List<PaymentChannelDTO>> selectPaymentChannel() {
        List<PaymentChannelDTO> list=paymentChannelService.getAllPaymentChannel();
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "查询成功", list);
    }

    /**
     * 获取通道列表
     * @return
     */
    @PostMapping("/channel/getCTypeList")
    public CommonResult<List<PaymentChannelDTO>> getCTypeList() {
        List<PaymentChannelDTO> list=paymentChannelService.selectPaymentChannelByType(1);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "查询成功", list);
    }

    /**
     * 获取通道详情
     * @return
     */
    @PostMapping("/getPaymentChannel")
    public CommonResult<PaymentChannelDTO> getPaymentChannel(@RequestBody PaymentChannelDTO paymentChannelDTO) {
        PaymentChannelDTO db=paymentChannelService.getPaymentChannelDTO(paymentChannelDTO.getId());
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "查询成功", db);
    }

    /**
     * 增加支付通道
     * @return
     */
    @PostMapping("/addPaymentChannel")
    public CommonResult addPaymentChannel(@RequestBody PaymentChannelDTO paymentChannelDTO) {
        if(paymentChannelDTO==null){
            throw new ParameterException("参数不能为空");
        }
        paymentChannelService.insertPaymentChannel(paymentChannelDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", "");
    }

    /**
     * 修改通道详情
     * @return
     */
    @PostMapping("/updatePaymentChannel")
    public CommonResult updatePaymentChannel(@RequestBody PaymentChannelDTO paymentChannelDTO) {
        if(paymentChannelDTO==null){
            throw new ParameterException("参数不能为空");
        }
        paymentChannelService.updatePaymentChannel(paymentChannelDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", "");
    }

    /**
     * 修改通道详情
     * @return
     */
    @PostMapping("/updatePaymentChannelUrl")
    public CommonResult updatePaymentChannelUrl(@RequestBody PaymentChannelDTO paymentChannelDTO) {
        if(paymentChannelDTO==null){
            throw new ParameterException("参数不能为空");
        }
        paymentChannelService.updatePaymentChannelUrl(paymentChannelDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", "");
    }

    /**
     * 修改通道平台KEY
     * @return
     * 返回公钥
     */
    @PostMapping("/updatePlatformKey")
    public CommonResult updatePlatformKey(@RequestBody PaymentChannelDTO paymentChannelDTO) {
        if(paymentChannelDTO==null){
            throw new ParameterException("参数不能为空");
        }
        String publicKey=paymentChannelService.updatePlatformKey(paymentChannelDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", publicKey);
    }


    /**
     * 修改通道产品费率
     * @return
     */
    @PostMapping("/updatePaymentChannelRate")
    public CommonResult updatePaymentChannelRate(@RequestBody PaymentChannelDTO paymentChannelDTO) {
        if(paymentChannelDTO==null){
            throw new ParameterException("参数不能为空");
        }
        paymentChannelService.updatePaymentChannelRate(paymentChannelDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", "");
    }

    /**
     * 修改通道禁用
     * @return
     */
    @PostMapping("/updatePaymentChannelStatu")
    public CommonResult updatePaymentChannelStatu(@RequestBody PaymentChannelDTO paymentChannelDTO) {
        if(paymentChannelDTO==null){
            throw new ParameterException("参数不能为空");
        }
        paymentChannelService.updatePaymentChannelStatus(paymentChannelDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", "");
    }


    /**
     * 修改商户通道
     * @return
     */
    @PostMapping("/updateMerchantChannel")
    public CommonResult updateMerchantChannel(@RequestBody MerchantChannelDTO merchantChannelDTO) {
        if(merchantChannelDTO==null){
            throw new ParameterException("参数不能为空");
        }
        paymentChannelService.updateMerchantChannel(merchantChannelDTO);
        return new CommonResult<>(CommonConstants.RETURN_SUCCESS, "修改成功", "");
    }

}
